/**
author: sailing
date: 2016/11/17
fun： 获取数据去画topo
***/
import fetchJson from './fetchJson'
import draw from './draw'
import Config from './config'
import counter from './counter'
import eventBus from '../eventBus'
import setPosition from './setPosition'
import dataJson from './data'
export default {
  draw (cy) {
    this.cy = cy
    fetchJson.getJson({
      self: this,
      url: 'topo/?biz=' + Config.bizx,
      callback: this.callback,
      error: this.error
    })
  },
  setDataCon (data) {
    var nodes = data.nodes
    for (var i=0; i<nodes.length; i++) {
      var position = {
        x: 100 + i*80,
        y: 100 + i*80
      }
      nodes[i]['position'] = position
      console.log('nodes 33:', nodes[i])
    }  
  },
  callback (data) {
    this.cy.maxZoom(1.5)
    this.cy.minZoom(0.3)
    dataJson.nodes = data.nodes
    dataJson.edges = data.edges
    setPosition.posi(data)
    this.cy.add(data.nodes)
    // this.cy.add(data.edges)
   // this.cy.layout({ name: 'breadthfirst' })
    /* this.cy.layout({
      name: 'breadthfirst',

      directed: true,
      padding: 10
    })
    */
    draw.setNodeStyle(this.cy)
    var coun = counter.getCounter(data.nodes)
    eventBus.bus.$emit('sendCounter', coun)
  },
  error () {
  }
}
